<template>
  <div>
      id:<input type="text" v-model="id"><br>
      名字:<input type="text" v-model="name"><br>
      年龄:<input type="text" v-model="age"><br>
      性别:<input type="text" v-model="gender"><br>
      所属班级:<select v-model="grade_id">
          <option :value="data.id" v-for="data in datas">{{data.name}}</option>
      </select><br>
      <button @click="add">添加</button>
  </div>
</template>

<script>
export default {
    name:'student_post',
    data(){
        return{
            datas:[],
            id:'',
            name:'',
            age:'',
            gender:'',
            grade_id:''
        }
    },
    methods:{
        getdata(){
            this.axios.get('asd/').then(res=>{
                this.datas=res.data
            })
        },
        add(){
            let data = new FormData();
            data.append('id',this.id)
            data.append('name',this.name)
            data.append('age',this.age)
            data.append('gender',this.gender)
            data.append('grade_id',this.grade_id)
            this.axios.post('ash/',data).then(res=>{
                this.$router.push('student_get')
            })
        }
    },
    mounted(){
        this.getdata()
    }

}
</script>

<style>

</style>